<template>
  <div class="confirm-dialog" v-if="visible" @click.self="handleCancel">
    <div class="dialog-content">
      <div class="dialog-header">
        <h3>{{ title }}</h3>
        <button class="close-btn" @click="handleCancel">×</button>
      </div>
      <div class="dialog-body">
        <p>{{ message }}</p>
      </div>
      <div class="dialog-footer">
        <button class="cancel-btn" @click="handleCancel">{{ cancelText }}</button>
        <button class="confirm-btn" @click="handleConfirm">{{ confirmText }}</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ConfirmDialog',
  props: {
    /**
     * 对话框是否可见
     */
    visible: {
      type: Boolean,
      default: false
    },
    /**
     * 对话框标题
     */
    title: {
      type: String,
      default: '确认操作'
    },
    /**
     * 对话框提示消息
     */
    message: {
      type: String,
      required: true
    },
    /**
     * 确认按钮文本
     */
    confirmText: {
      type: String,
      default: '确定'
    },
    /**
     * 取消按钮文本
     */
    cancelText: {
      type: String,
      default: '取消'
    }
  },
  methods: {
    /**
     * 处理确认按钮点击
     */
    handleConfirm() {
      this.$emit('confirm');
    },
    /**
     * 处理取消按钮点击
     */
    handleCancel() {
      this.$emit('cancel');
    }
  }
};
</script>

<style scoped>
.confirm-dialog {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.dialog-content {
  background-color: white;
  border-radius: 8px;
  width: 400px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  overflow: hidden;
}

.dialog-header {
  padding: 20px;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dialog-header h3 {
  margin: 0;
  color: #333;
  font-size: 16px;
  font-weight: 500;
}

.close-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #999;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.close-btn:hover {
  color: #333;
}

.dialog-body {
  padding: 20px;
}

.dialog-body p {
  margin: 0;
  color: #666;
  line-height: 1.6;
}

.dialog-footer {
  padding: 15px 20px;
  border-top: 1px solid #f0f0f0;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.cancel-btn,
.confirm-btn {
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.3s;
  border: 1px solid #d9d9d9;
}

.cancel-btn {
  background-color: white;
  color: #666;
}

.cancel-btn:hover {
  border-color: #40a9ff;
  color: #40a9ff;
}

.confirm-btn {
  background-color: #1890ff;
  color: white;
  border-color: #1890ff;
}

.confirm-btn:hover {
  background-color: #40a9ff;
  border-color: #40a9ff;
}
</style>